package com.ctshk.rpc.airexpress.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.IsDeletedCode;
import com.ctshk.common.enums.SystemError;
import com.ctshk.common.exception.BusinessException;
import com.ctshk.common.utils.DateUtil;
import com.ctshk.common.utils.EntityUtil;
import com.ctshk.common.utils.SnowflakeIdWorker;
import com.ctshk.rpc.airexpress.base.CustomBaseMapper;


import com.ctshk.rpc.airexpress.dto.*;
import com.ctshk.rpc.airexpress.entity.*;
import com.ctshk.rpc.airexpress.mapper.*;
import com.ctshk.rpc.airexpress.req.*;
import com.ctshk.rpc.airexpress.req.cache.CacheOpsReq;
import com.ctshk.rpc.airexpress.service.IAirportExpressAppService;
import com.ctshk.rpc.airexpress.service.IAirportExpressIncreaseStrategyService;
import com.ctshk.rpc.airexpress.strategy.AirportExpressStrategyRuleValidator;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import javax.validation.Valid;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;

/**
 * <p>
 * 产品加幅策略表 服务实现类
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-02-05
 */
@Slf4j
@DubboService
public class AirportExpressIncreaseStrategyServiceImpl extends ServiceImpl<AirportExpressIncreaseStrategyMapper, AirportExpressIncreaseStrategy> implements IAirportExpressIncreaseStrategyService {
    @Autowired
    private AirportExpressIncreaseStrategyMapper airportExpressIncreaseStrategyMapper;
    @Autowired
    private AirportExpressIncreaseStrategyDateMapper airportExpressIncreaseStrategyDateMapper;
    @Autowired
    private AirportExpressIncreaseStrategyRuleMapper airportExpressIncreaseStrategyRuleMapper;
    @Autowired
    private AirportExpressChannelOfflineAgentCustomMapper airportExpressChannelOfflineAgentCustomMapper;
    @Autowired
    private AirportExpressChannelOfflineSelfCustomMapper airportExpressChannelOfflineSelfCustomMapper;
    @Autowired
    private AirportExpressChannelOnlineSelfPlatformMapper airportExpressChannelOnlineSelfPlatformMapper;
    @Autowired
    private AirportExpressChannelOnlineThirdPlatformMapper airportExpressChannelOnlineThirdPlatformMapper;
    @Autowired
    private AirportExpressMapper airportExpressMapper;
    @DubboReference
    private IAirportExpressAppService airportExpressAppService;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result save(AirportExpressIncreaseStrategySaveBatchReq airportExpressIncreaseStrategySaveBatchReq, Long userId) {
        Long airportExpressId = airportExpressIncreaseStrategySaveBatchReq.getAirportExpressIdList().get(0);
        List<AirportExpressIncreaseStrategyReq> airportExpressIncreaseStrategyReqList = airportExpressIncreaseStrategySaveBatchReq.getAirportExpressIncreaseStrategyList();
        AirportExpress airportExpress = airportExpressMapper.selectById(airportExpressId);
        if (null == airportExpress) {
            return Result.failed(SystemError.AIREXPRESS_50004);
        }
        checkSaveData(Arrays.asList(airportExpress), airportExpressIncreaseStrategyReqList);
        // 插入加幅策略列表
        List<AirportExpressIncreaseStrategy> aeIncreaseStrategyInsertList = new ArrayList<>();
        List<AirportExpressIncreaseStrategyDate> aeIncreaseStrategyDateInsertList = new ArrayList<>();
        List<AirportExpressIncreaseStrategyRule> aeIncreaseStrategyRuleInsertList = new ArrayList<>();
        List<AirportExpressChannelOfflineAgentCustom> aeChannelOfflineAgentCustomInsertList = new ArrayList<>();
        List<AirportExpressChannelOfflineSelfCustom> aeChannelOfflineSelfCustomInsertList = new ArrayList<>();
        List<AirportExpressChannelOnlineSelfPlatform> aeChannelOnlineSelfPlatformInsertList = new ArrayList<>();
        List<AirportExpressChannelOnlineThirdPlatform> aeChannelOnlineThirdPlatformInsertList = new ArrayList<>();
        // 更新加幅策略列表
        List<AirportExpressIncreaseStrategy> aeIncreaseStrategyUpdateList = new ArrayList<>();
        List<AirportExpressIncreaseStrategyDate> aeIncreaseStrategyDateUpdateList = new ArrayList<>();
        List<AirportExpressIncreaseStrategyRule> aeIncreaseStrategyRuleUpdateList = new ArrayList<>();
        List<AirportExpressChannelOfflineAgentCustom> aeChannelOfflineAgentCustomUpdateList = new ArrayList<>();
        List<AirportExpressChannelOfflineSelfCustom> aeChannelOfflineSelfCustomUpdateList = new ArrayList<>();
        List<AirportExpressChannelOnlineSelfPlatform> aeChannelOnlineSelfPlatformUpdateList = new ArrayList<>();
        List<AirportExpressChannelOnlineThirdPlatform> aeChannelOnlineThirdPlatformUpdateList = new ArrayList<>();
        // 不需删除加幅策略ID列表
        List<Long> aeIncreaseStrategyIdList = new ArrayList<>();
        List<Long> aeIncreaseStrategyDateIdList = new ArrayList<>();
        List<Long> aeIncreaseStrategyRuleIdList = new ArrayList<>();
        List<Long> aeChannelOfflineAgentCustomIdList = new ArrayList<>();
        List<Long> aeChannelOfflineSelfCustomIdList = new ArrayList<>();
        List<Long> aeChannelOnlineSelfPlatformIdList = new ArrayList<>();
        List<Long> aeChannelOnlineThirdPlatformIdList = new ArrayList<>();
        LocalDateTime nowDateTime = LocalDateTime.now();
        // 查询当前机场快线-策略IDList
        List<Long> deleteStrategyIdList = airportExpressIncreaseStrategyMapper.selectIdListByAirportExpressIds(Arrays.asList(airportExpressId));
        for (AirportExpressIncreaseStrategyReq increaseStrategyReq : airportExpressIncreaseStrategyReqList) {
            // 构建加幅策略
            AirportExpressIncreaseStrategy increaseStrategy = EntityUtil.copy(increaseStrategyReq, AirportExpressIncreaseStrategy.class);
            increaseStrategy.setModifiedId(userId);
            increaseStrategy.setGmtModified(nowDateTime);
            if (increaseStrategy.getId() == null) {
                increaseStrategy.setId(SnowflakeIdWorker.nextId());
                increaseStrategy.setCreateId(userId);
                increaseStrategy.setGmtCreate(nowDateTime);
                increaseStrategy.setIsDeleted(IsDeletedCode.NO.getCode());
                aeIncreaseStrategyInsertList.add(increaseStrategy);
            } else {
                // 剔除传过来的策略ID，剩下的是需要删除的
                if (deleteStrategyIdList.contains(increaseStrategy.getId())) {
                    deleteStrategyIdList.remove(increaseStrategy.getId());
                }
                aeIncreaseStrategyUpdateList.add(increaseStrategy);
                aeIncreaseStrategyIdList.add(increaseStrategy.getId());
            }
            increaseStrategy.setAirportExpressId(airportExpressId);
            // 构建加幅策略日期段
            List<AirportExpressIncreaseStrategyDate> increaseStrategyDateList = EntityUtil.copyList(increaseStrategyReq.getAirportExpressIncreaseStrategyDateList(), AirportExpressIncreaseStrategyDate.class);
            for (AirportExpressIncreaseStrategyDate strategyDate : increaseStrategyDateList) {
                if (strategyDate.getId() == null) {
                    strategyDate.setId(SnowflakeIdWorker.nextId());
                    aeIncreaseStrategyDateInsertList.add(strategyDate);
                } else {
                    aeIncreaseStrategyDateUpdateList.add(strategyDate);
                    aeIncreaseStrategyDateIdList.add(strategyDate.getId());
                }
                strategyDate.setIncreaseStrategyId(increaseStrategy.getId());
            }
            // 构建加幅策略-线下自营规则-所有
            if (increaseStrategy.getSelfSalePermissionType() == OrderAirexpressConstants.SALE_CHANNEL_TYPE_ALL) {
                AirportExpressIncreaseStrategyRule increaseStrategyRule = EntityUtil.copy(increaseStrategyReq.getAirportExpressIncreaseStrategySelfRule(), AirportExpressIncreaseStrategyRule.class);
                if (increaseStrategyRule.getId() == null) {
                    increaseStrategyRule.setId(SnowflakeIdWorker.nextId());
                    aeIncreaseStrategyRuleInsertList.add(increaseStrategyRule);
                } else {
                    aeIncreaseStrategyRuleUpdateList.add(increaseStrategyRule);
                    aeIncreaseStrategyRuleIdList.add(increaseStrategyRule.getId());
                }
                increaseStrategyRule.setIncreaseStrategyId(increaseStrategy.getId());
                increaseStrategyRule.setSoldNumber(null);
                increaseStrategy.setSelfSalePermissionId(increaseStrategyRule.getId());
            }
            // 构建加幅策略-线下自营规则-指定
            if (increaseStrategyReq.getSelfSalePermissionType() == OrderAirexpressConstants.SALE_CHANNEL_TYPE_SELECTED && CollectionUtils.isNotEmpty(increaseStrategyReq.getAirportExpressChannelOfflineSelfCustomList())) {
                increaseStrategyReq.getAirportExpressChannelOfflineSelfCustomList().forEach(channelOfflineSelfCustomReq -> {
                    AirportExpressChannelOfflineSelfCustom channelOfflineSelfCustom = EntityUtil.copy(channelOfflineSelfCustomReq, AirportExpressChannelOfflineSelfCustom.class);
                    if (channelOfflineSelfCustom.getId() == null) {
                        channelOfflineSelfCustom.setId(SnowflakeIdWorker.nextId());
                        aeChannelOfflineSelfCustomInsertList.add(channelOfflineSelfCustom);
                    } else {
                        aeChannelOfflineSelfCustomUpdateList.add(channelOfflineSelfCustom);
                        aeChannelOfflineSelfCustomIdList.add(channelOfflineSelfCustom.getId());
                    }
                    channelOfflineSelfCustom.setIncreaseStrategyId(increaseStrategy.getId());
                    channelOfflineSelfCustom.setCreateId(userId);
                    channelOfflineSelfCustom.setGmtCreate(nowDateTime);
                    channelOfflineSelfCustom.setModifiedId(userId);
                    channelOfflineSelfCustom.setGmtModified(nowDateTime);
                    channelOfflineSelfCustom.setIsDeleted(IsDeletedCode.NO.getCode());
                    // 插入加幅规则
                    AirportExpressIncreaseStrategyRule increaseStrategyRule = EntityUtil.copy(channelOfflineSelfCustomReq.getAirportExpressIncreaseStrategyRule(), AirportExpressIncreaseStrategyRule.class);
                    if (increaseStrategyRule.getId() == null) {
                        increaseStrategyRule.setId(SnowflakeIdWorker.nextId());
                        aeIncreaseStrategyRuleInsertList.add(increaseStrategyRule);
                    } else {
                        aeIncreaseStrategyRuleUpdateList.add(increaseStrategyRule);
                        aeIncreaseStrategyRuleIdList.add(increaseStrategyRule.getId());
                    }
                    increaseStrategyRule.setIncreaseStrategyId(increaseStrategy.getId());
                    increaseStrategyRule.setCustomId(channelOfflineSelfCustom.getId());
                    increaseStrategyRule.setSoldNumber(null);
                });
            }
            // 构建加幅策略-线下代理规则-所有
            if (increaseStrategy.getAgentSalePermissionType() == OrderAirexpressConstants.SALE_CHANNEL_TYPE_ALL) {
                AirportExpressIncreaseStrategyRule increaseStrategyRule = EntityUtil.copy(increaseStrategyReq.getAirportExpressIncreaseStrategyAgentRule(), AirportExpressIncreaseStrategyRule.class);
                if (increaseStrategyRule.getId() == null) {
                    increaseStrategyRule.setId(SnowflakeIdWorker.nextId());
                    aeIncreaseStrategyRuleInsertList.add(increaseStrategyRule);
                } else {
                    aeIncreaseStrategyRuleUpdateList.add(increaseStrategyRule);
                    aeIncreaseStrategyRuleIdList.add(increaseStrategyRule.getId());
                }
                increaseStrategyRule.setIncreaseStrategyId(increaseStrategy.getId());
                increaseStrategyRule.setSoldNumber(null);
                increaseStrategy.setAgentSalePermissionId(increaseStrategyRule.getId());
            }
            // 构建加幅策略-线下代理规则-指定
            if (increaseStrategyReq.getAgentSalePermissionType() == OrderAirexpressConstants.SALE_CHANNEL_TYPE_SELECTED && CollectionUtils.isNotEmpty(increaseStrategyReq.getAirportExpressChannelOfflineAgentCustomList())) {
                increaseStrategyReq.getAirportExpressChannelOfflineAgentCustomList().forEach(channelOfflineAgentCustomReq -> {
                    AirportExpressChannelOfflineAgentCustom channelOfflineAgentCustom = EntityUtil.copy(channelOfflineAgentCustomReq, AirportExpressChannelOfflineAgentCustom.class);
                    if (channelOfflineAgentCustom.getId() == null) {
                        channelOfflineAgentCustom.setId(SnowflakeIdWorker.nextId());
                        aeChannelOfflineAgentCustomInsertList.add(channelOfflineAgentCustom);
                    } else {
                        aeChannelOfflineAgentCustomUpdateList.add(channelOfflineAgentCustom);
                        aeChannelOfflineAgentCustomIdList.add(channelOfflineAgentCustom.getId());
                    }
                    channelOfflineAgentCustom.setIncreaseStrategyId(increaseStrategy.getId());
                    channelOfflineAgentCustom.setCreateId(userId);
                    channelOfflineAgentCustom.setGmtCreate(nowDateTime);
                    channelOfflineAgentCustom.setModifiedId(userId);
                    channelOfflineAgentCustom.setGmtModified(nowDateTime);
                    channelOfflineAgentCustom.setIsDeleted(IsDeletedCode.NO.getCode());
                    // 插入加幅规则
                    AirportExpressIncreaseStrategyRule increaseStrategyRule = EntityUtil.copy(channelOfflineAgentCustomReq.getAirportExpressIncreaseStrategyRule(), AirportExpressIncreaseStrategyRule.class);
                    if (increaseStrategyRule.getId() == null) {
                        increaseStrategyRule.setId(SnowflakeIdWorker.nextId());
                        aeIncreaseStrategyRuleInsertList.add(increaseStrategyRule);
                    } else {
                        aeIncreaseStrategyRuleUpdateList.add(increaseStrategyRule);
                        aeIncreaseStrategyRuleIdList.add(increaseStrategyRule.getId());
                    }
                    increaseStrategyRule.setIncreaseStrategyId(increaseStrategy.getId());
                    increaseStrategyRule.setCustomId(channelOfflineAgentCustom.getId());
                    increaseStrategyRule.setSoldNumber(null);
                });
            }
            // 线上自营
            if (CollectionUtils.isNotEmpty(increaseStrategyReq.getAirportExpressChannelOnlineSelfPlatformList())) {
                increaseStrategyReq.getAirportExpressChannelOnlineSelfPlatformList().forEach(channelOnlineSelfPlatformReq -> {
                    AirportExpressChannelOnlineSelfPlatform channelOnlineSelfPlatform = EntityUtil.copy(channelOnlineSelfPlatformReq, AirportExpressChannelOnlineSelfPlatform.class);
                    if (channelOnlineSelfPlatform.getId() == null) {
                        channelOnlineSelfPlatform.setId(SnowflakeIdWorker.nextId());
                        aeChannelOnlineSelfPlatformInsertList.add(channelOnlineSelfPlatform);
                    } else {
                        aeChannelOnlineSelfPlatformUpdateList.add(channelOnlineSelfPlatform);
                        aeChannelOnlineSelfPlatformIdList.add(channelOnlineSelfPlatform.getId());
                    }
                    channelOnlineSelfPlatform.setIncreaseStrategyId(increaseStrategy.getId());
                    channelOnlineSelfPlatform.setCreateId(userId);
                    channelOnlineSelfPlatform.setGmtCreate(nowDateTime);
                    channelOnlineSelfPlatform.setModifiedId(userId);
                    channelOnlineSelfPlatform.setGmtModified(nowDateTime);
                    channelOnlineSelfPlatform.setIsDeleted(IsDeletedCode.NO.getCode());
                    // 插入加幅规则
                    AirportExpressIncreaseStrategyRule increaseStrategyRule = EntityUtil.copy(channelOnlineSelfPlatformReq.getAirportExpressIncreaseStrategyRule(), AirportExpressIncreaseStrategyRule.class);
                    if (increaseStrategyRule.getId() == null) {
                        increaseStrategyRule.setId(SnowflakeIdWorker.nextId());
                        aeIncreaseStrategyRuleInsertList.add(increaseStrategyRule);
                    } else {
                        aeIncreaseStrategyRuleUpdateList.add(increaseStrategyRule);
                        aeIncreaseStrategyRuleIdList.add(increaseStrategyRule.getId());
                    }
                    increaseStrategyRule.setIncreaseStrategyId(increaseStrategy.getId());
                    increaseStrategyRule.setCustomId(channelOnlineSelfPlatform.getId());
                    increaseStrategyRule.setSoldNumber(null);
                });
            }
            // 线上第三方
            if (CollectionUtils.isNotEmpty(increaseStrategyReq.getAirportExpressChannelOnlineThirdPlatformList())) {
                increaseStrategyReq.getAirportExpressChannelOnlineThirdPlatformList().forEach(channelOnlineThirdPlatformReq -> {
                    AirportExpressChannelOnlineThirdPlatform channelOnlineThirdPlatform = EntityUtil.copy(channelOnlineThirdPlatformReq, AirportExpressChannelOnlineThirdPlatform.class);
                    if (channelOnlineThirdPlatform.getId() == null) {
                        channelOnlineThirdPlatform.setId(SnowflakeIdWorker.nextId());
                        aeChannelOnlineThirdPlatformInsertList.add(channelOnlineThirdPlatform);
                    } else {
                        aeChannelOnlineThirdPlatformUpdateList.add(channelOnlineThirdPlatform);
                        aeChannelOnlineThirdPlatformIdList.add(channelOnlineThirdPlatform.getId());
                    }
                    channelOnlineThirdPlatform.setIncreaseStrategyId(increaseStrategy.getId());
                    channelOnlineThirdPlatform.setCreateId(userId);
                    channelOnlineThirdPlatform.setGmtCreate(nowDateTime);
                    channelOnlineThirdPlatform.setModifiedId(userId);
                    channelOnlineThirdPlatform.setGmtModified(nowDateTime);
                    channelOnlineThirdPlatform.setIsDeleted(IsDeletedCode.NO.getCode());
                    // 插入加幅规则
                    AirportExpressIncreaseStrategyRule increaseStrategyRule = EntityUtil.copy(channelOnlineThirdPlatformReq.getAirportExpressIncreaseStrategyRule(), AirportExpressIncreaseStrategyRule.class);
                    if (increaseStrategyRule.getId() == null) {
                        increaseStrategyRule.setId(SnowflakeIdWorker.nextId());
                        aeIncreaseStrategyRuleInsertList.add(increaseStrategyRule);
                    } else {
                        aeIncreaseStrategyRuleUpdateList.add(increaseStrategyRule);
                        aeIncreaseStrategyRuleIdList.add(increaseStrategyRule.getId());
                    }
                    increaseStrategyRule.setIncreaseStrategyId(increaseStrategy.getId());
                    increaseStrategyRule.setCustomId(channelOnlineThirdPlatform.getId());
                    increaseStrategyRule.setSoldNumber(null);
                });
            }
        }

        if (CollectionUtils.isNotEmpty(deleteStrategyIdList)) {// 删除入参中不存在的ID列表
            airportExpressIncreaseStrategyMapper.delete(new QueryWrapper<AirportExpressIncreaseStrategy>().in("id", deleteStrategyIdList));
            airportExpressIncreaseStrategyDateMapper.delete(new QueryWrapper<AirportExpressIncreaseStrategyDate>().in("increase_strategy_id", deleteStrategyIdList));
            airportExpressIncreaseStrategyRuleMapper.delete(new QueryWrapper<AirportExpressIncreaseStrategyRule>().in("increase_strategy_id", deleteStrategyIdList));
            airportExpressChannelOfflineSelfCustomMapper.delete(new QueryWrapper<AirportExpressChannelOfflineSelfCustom>().in("increase_strategy_id", deleteStrategyIdList));
            airportExpressChannelOfflineAgentCustomMapper.delete(new QueryWrapper<AirportExpressChannelOfflineAgentCustom>().in("increase_strategy_id", deleteStrategyIdList));
            airportExpressChannelOnlineSelfPlatformMapper.delete(new QueryWrapper<AirportExpressChannelOnlineSelfPlatform>().in("increase_strategy_id", deleteStrategyIdList));
            airportExpressChannelOnlineThirdPlatformMapper.delete(new QueryWrapper<AirportExpressChannelOnlineThirdPlatform>().in("increase_strategy_id", deleteStrategyIdList));
        }
        if (CollectionUtils.isNotEmpty(aeIncreaseStrategyDateIdList)) {// 删除不存在的ID列表
            airportExpressIncreaseStrategyDateMapper.delete(new QueryWrapper<AirportExpressIncreaseStrategyDate>().notIn("id", aeIncreaseStrategyDateIdList));
        } else if (CollectionUtils.isNotEmpty(aeIncreaseStrategyIdList)) {// 删除不存在的ID列表
            airportExpressIncreaseStrategyDateMapper.delete(new QueryWrapper<AirportExpressIncreaseStrategyDate>().in("increase_strategy_id", aeIncreaseStrategyIdList));
        }
        if (CollectionUtils.isNotEmpty(aeIncreaseStrategyRuleIdList)) {
            airportExpressIncreaseStrategyRuleMapper.delete(new QueryWrapper<AirportExpressIncreaseStrategyRule>().notIn("id", aeIncreaseStrategyRuleIdList));
        } else if (CollectionUtils.isNotEmpty(aeIncreaseStrategyIdList)) {
            airportExpressIncreaseStrategyRuleMapper.delete(new QueryWrapper<AirportExpressIncreaseStrategyRule>().in("increase_strategy_id", aeIncreaseStrategyIdList));
        }
        if (CollectionUtils.isNotEmpty(aeChannelOfflineSelfCustomIdList)) {
            airportExpressChannelOfflineSelfCustomMapper.delete(new QueryWrapper<AirportExpressChannelOfflineSelfCustom>().notIn("id", aeChannelOfflineSelfCustomIdList));
        } else if (CollectionUtils.isNotEmpty(aeIncreaseStrategyIdList)) {
            airportExpressChannelOfflineSelfCustomMapper.delete(new QueryWrapper<AirportExpressChannelOfflineSelfCustom>().in("increase_strategy_id", aeIncreaseStrategyIdList));
        }
        if (CollectionUtils.isNotEmpty(aeChannelOfflineAgentCustomIdList)) {
            airportExpressChannelOfflineAgentCustomMapper.delete(new QueryWrapper<AirportExpressChannelOfflineAgentCustom>().notIn("id", aeChannelOfflineAgentCustomIdList));
        } else if (CollectionUtils.isNotEmpty(aeIncreaseStrategyIdList)) {
            airportExpressChannelOfflineAgentCustomMapper.delete(new QueryWrapper<AirportExpressChannelOfflineAgentCustom>().in("increase_strategy_id", aeIncreaseStrategyIdList));
        }
        if (CollectionUtils.isNotEmpty(aeChannelOnlineSelfPlatformIdList)) {
            airportExpressChannelOnlineSelfPlatformMapper.delete(new QueryWrapper<AirportExpressChannelOnlineSelfPlatform>().notIn("id", aeChannelOnlineSelfPlatformIdList));
        } else if (CollectionUtils.isNotEmpty(aeIncreaseStrategyIdList)) {
            airportExpressChannelOnlineSelfPlatformMapper.delete(new QueryWrapper<AirportExpressChannelOnlineSelfPlatform>().in("increase_strategy_id", aeIncreaseStrategyIdList));
        }
        if (CollectionUtils.isNotEmpty(aeChannelOnlineThirdPlatformIdList)) {
            airportExpressChannelOnlineThirdPlatformMapper.delete(new QueryWrapper<AirportExpressChannelOnlineThirdPlatform>().notIn("id", aeChannelOnlineThirdPlatformIdList));
        } else if (CollectionUtils.isNotEmpty(aeIncreaseStrategyIdList)) {
            airportExpressChannelOnlineThirdPlatformMapper.delete(new QueryWrapper<AirportExpressChannelOnlineThirdPlatform>().in("increase_strategy_id", aeIncreaseStrategyIdList));
        }
        // 更新
        updateBatchSomeColumn(aeIncreaseStrategyUpdateList, airportExpressIncreaseStrategyMapper);
        updateBatchSomeColumn(aeIncreaseStrategyDateUpdateList, airportExpressIncreaseStrategyDateMapper);
        updateBatchSomeColumn(aeIncreaseStrategyRuleUpdateList, airportExpressIncreaseStrategyRuleMapper);
        updateBatchSomeColumn(aeChannelOfflineSelfCustomUpdateList, airportExpressChannelOfflineSelfCustomMapper);
        updateBatchSomeColumn(aeChannelOfflineAgentCustomUpdateList, airportExpressChannelOfflineAgentCustomMapper);
        updateBatchSomeColumn(aeChannelOnlineSelfPlatformUpdateList, airportExpressChannelOnlineSelfPlatformMapper);
        updateBatchSomeColumn(aeChannelOnlineThirdPlatformUpdateList, airportExpressChannelOnlineThirdPlatformMapper);
        // 插入
        insertBatchSomeColumn(aeIncreaseStrategyInsertList, airportExpressIncreaseStrategyMapper);
        insertBatchSomeColumn(aeIncreaseStrategyDateInsertList, airportExpressIncreaseStrategyDateMapper);
        insertBatchSomeColumn(aeIncreaseStrategyRuleInsertList, airportExpressIncreaseStrategyRuleMapper);
        insertBatchSomeColumn(aeChannelOfflineSelfCustomInsertList, airportExpressChannelOfflineSelfCustomMapper);
        insertBatchSomeColumn(aeChannelOfflineAgentCustomInsertList, airportExpressChannelOfflineAgentCustomMapper);
        insertBatchSomeColumn(aeChannelOnlineSelfPlatformInsertList, airportExpressChannelOnlineSelfPlatformMapper);
        insertBatchSomeColumn(aeChannelOnlineThirdPlatformInsertList, airportExpressChannelOnlineThirdPlatformMapper);
        /**
         * 异步更新产品redis缓存
         */
        CompletableFuture.runAsync(() -> {
            log.info("【机场快线-保存加幅策略】更新redis缓存, data:{}", airportExpressId);
            airportExpressAppService.cacheInit();
        });
        return Result.success();
    }

    private void updateBatchSomeColumn(List list, CustomBaseMapper mapper) {
        if (CollectionUtils.isNotEmpty(list)) {
            for (Object o : list) {
                mapper.updateById(o);
            }
        }
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result saveBatch(@Valid AirportExpressIncreaseStrategySaveBatchReq aeIncreaseStrategySaveBatchReq, Long userId) {
        List<Long> airportExpressIdList = aeIncreaseStrategySaveBatchReq.getAirportExpressIdList();
        List<AirportExpress> airportExpresses = airportExpressMapper.selectBatchIds(airportExpressIdList);
        if (CollectionUtils.isEmpty(airportExpresses)) {
            return Result.failed(SystemError.AIREXPRESS_50004);
        }
        List<AirportExpressIncreaseStrategyReq> airportExpressIncreaseStrategyReqList = aeIncreaseStrategySaveBatchReq.getAirportExpressIncreaseStrategyList();

        checkSaveData(airportExpresses, airportExpressIncreaseStrategyReqList);

        LocalDateTime nowDateTime = LocalDateTime.now();
        // 删除加幅策略
        deleteStrategyByAirportExpressId(airportExpressIdList);
        // 插入加幅策略
        List<AirportExpressIncreaseStrategy> airportExpressIncreaseStrategyList = new ArrayList<>();
        List<AirportExpressIncreaseStrategyRule> airportExpressIncreaseStrategyRuleList = new ArrayList<>();
        List<AirportExpressIncreaseStrategyDate> airportExpressIncreaseStrategyDateList = new ArrayList<>();
        List<AirportExpressChannelOfflineSelfCustom> airportExpressChannelOfflineSelfCustomList = new ArrayList<>();
        List<AirportExpressChannelOfflineAgentCustom> airportExpressChannelOfflineAgentCustomList = new ArrayList<>();
        List<AirportExpressChannelOnlineSelfPlatform> airportExpressChannelOnlineSelfPlatformList = new ArrayList<>();
        List<AirportExpressChannelOnlineThirdPlatform> airportExpressChannelOnlineThirdPlatformList = new ArrayList<>();
        for (Long airportExpressId : airportExpressIdList) {
            for (AirportExpressIncreaseStrategyReq increaseStrategyReq : airportExpressIncreaseStrategyReqList) {
                // 构建加幅策略
                AirportExpressIncreaseStrategy increaseStrategy = EntityUtil.copy(increaseStrategyReq, AirportExpressIncreaseStrategy.class);
                increaseStrategy.setAirportExpressId(airportExpressId);
                increaseStrategy.setId(SnowflakeIdWorker.nextId());
                // 构建加幅策略日期段
                List<AirportExpressIncreaseStrategyDate> increaseStrategyDateList = EntityUtil.copyList(increaseStrategyReq.getAirportExpressIncreaseStrategyDateList(), AirportExpressIncreaseStrategyDate.class);
                for (AirportExpressIncreaseStrategyDate strategyDate : increaseStrategyDateList) {
                    strategyDate.setId(SnowflakeIdWorker.nextId());
                    strategyDate.setIncreaseStrategyId(increaseStrategy.getId());
                }
                airportExpressIncreaseStrategyDateList.addAll(increaseStrategyDateList);
                // 构建加幅策略-线下自营规则-所有
                if (increaseStrategy.getSelfSalePermissionType() != null) {
                    if (increaseStrategy.getSelfSalePermissionType() == OrderAirexpressConstants.SALE_CHANNEL_TYPE_ALL) {
                        AirportExpressIncreaseStrategyRule increaseStrategyRule = EntityUtil.copy(increaseStrategyReq.getAirportExpressIncreaseStrategySelfRule(), AirportExpressIncreaseStrategyRule.class);
                        increaseStrategyRule.setId(SnowflakeIdWorker.nextId());
                        increaseStrategyRule.setIncreaseStrategyId(increaseStrategy.getId());
                        increaseStrategyRule.setSoldNumber(null);
                        increaseStrategy.setSelfSalePermissionId(increaseStrategyRule.getId());
                        airportExpressIncreaseStrategyRuleList.add(increaseStrategyRule);
                    }
                    // 构建加幅策略-线下自营规则-指定
                    if (increaseStrategyReq.getSelfSalePermissionType() == OrderAirexpressConstants.SALE_CHANNEL_TYPE_SELECTED && CollectionUtils.isNotEmpty(increaseStrategyReq.getAirportExpressChannelOfflineSelfCustomList())) {
                        increaseStrategyReq.getAirportExpressChannelOfflineSelfCustomList().forEach(channelOfflineSelfCustomReq -> {
                            AirportExpressChannelOfflineSelfCustom channelOfflineSelfCustom = EntityUtil.copy(channelOfflineSelfCustomReq, AirportExpressChannelOfflineSelfCustom.class);
                            channelOfflineSelfCustom.setId(SnowflakeIdWorker.nextId());
                            channelOfflineSelfCustom.setIncreaseStrategyId(increaseStrategy.getId());
                            channelOfflineSelfCustom.setCreateId(userId);
                            channelOfflineSelfCustom.setGmtCreate(nowDateTime);
                            channelOfflineSelfCustom.setModifiedId(userId);
                            channelOfflineSelfCustom.setGmtModified(nowDateTime);
                            channelOfflineSelfCustom.setIsDeleted(IsDeletedCode.NO.getCode());
                            airportExpressChannelOfflineSelfCustomList.add(channelOfflineSelfCustom);
                            // 插入加幅规则
                            AirportExpressIncreaseStrategyRule increaseStrategyRule = EntityUtil.copy(channelOfflineSelfCustomReq.getAirportExpressIncreaseStrategyRule(), AirportExpressIncreaseStrategyRule.class);
                            increaseStrategyRule.setId(SnowflakeIdWorker.nextId());
                            increaseStrategyRule.setIncreaseStrategyId(increaseStrategy.getId());
                            increaseStrategyRule.setCustomId(channelOfflineSelfCustom.getId());
                            increaseStrategyRule.setSoldNumber(null);
                            airportExpressIncreaseStrategyRuleList.add(increaseStrategyRule);
                        });
                    }
                }
                // 构建加幅策略-线下代理规则-所有
                if (increaseStrategy.getAgentSalePermissionType() != null) {
                    if (increaseStrategy.getAgentSalePermissionType() == OrderAirexpressConstants.SALE_CHANNEL_TYPE_ALL) {
                        AirportExpressIncreaseStrategyRule increaseStrategyRule = EntityUtil.copy(increaseStrategyReq.getAirportExpressIncreaseStrategyAgentRule(), AirportExpressIncreaseStrategyRule.class);
                        increaseStrategyRule.setId(SnowflakeIdWorker.nextId());
                        increaseStrategyRule.setIncreaseStrategyId(increaseStrategy.getId());
                        increaseStrategyRule.setSoldNumber(null);
                        increaseStrategy.setAgentSalePermissionId(increaseStrategyRule.getId());
                        airportExpressIncreaseStrategyRuleList.add(increaseStrategyRule);
                    }
                    // 构建加幅策略-线下代理规则-指定
                    if (increaseStrategyReq.getAgentSalePermissionType() == OrderAirexpressConstants.SALE_CHANNEL_TYPE_SELECTED && CollectionUtils.isNotEmpty(increaseStrategyReq.getAirportExpressChannelOfflineAgentCustomList())) {
                        for (AirportExpressChannelOfflineAgentCustomReq channelOfflineAgentCustomReq : increaseStrategyReq.getAirportExpressChannelOfflineAgentCustomList()) {
                            AirportExpressChannelOfflineAgentCustom channelOfflineAgentCustom = EntityUtil.copy(channelOfflineAgentCustomReq, AirportExpressChannelOfflineAgentCustom.class);
                            channelOfflineAgentCustom.setId(SnowflakeIdWorker.nextId());
                            channelOfflineAgentCustom.setIncreaseStrategyId(increaseStrategy.getId());
                            channelOfflineAgentCustom.setCreateId(userId);
                            channelOfflineAgentCustom.setGmtCreate(nowDateTime);
                            channelOfflineAgentCustom.setModifiedId(userId);
                            channelOfflineAgentCustom.setGmtModified(nowDateTime);
                            channelOfflineAgentCustom.setIsDeleted(IsDeletedCode.NO.getCode());
                            airportExpressChannelOfflineAgentCustomList.add(channelOfflineAgentCustom);
                            // 插入加幅规则
                            AirportExpressIncreaseStrategyRule increaseStrategyRule = EntityUtil.copy(channelOfflineAgentCustomReq.getAirportExpressIncreaseStrategyRule(), AirportExpressIncreaseStrategyRule.class);
                            increaseStrategyRule.setId(SnowflakeIdWorker.nextId());
                            increaseStrategyRule.setIncreaseStrategyId(increaseStrategy.getId());
                            increaseStrategyRule.setCustomId(channelOfflineAgentCustom.getId());
                            increaseStrategyRule.setSoldNumber(null);
                            airportExpressIncreaseStrategyRuleList.add(increaseStrategyRule);
                        }
                    }
                }
                // 线上自营
                if (CollectionUtils.isNotEmpty(increaseStrategyReq.getAirportExpressChannelOnlineSelfPlatformList())) {
                    increaseStrategyReq.getAirportExpressChannelOnlineSelfPlatformList().forEach(channelOnlineSelfPlatformReq -> {
                        AirportExpressChannelOnlineSelfPlatform channelOnlineSelfPlatform = EntityUtil.copy(channelOnlineSelfPlatformReq, AirportExpressChannelOnlineSelfPlatform.class);
                        channelOnlineSelfPlatform.setId(SnowflakeIdWorker.nextId());
                        channelOnlineSelfPlatform.setIncreaseStrategyId(increaseStrategy.getId());
                        channelOnlineSelfPlatform.setCreateId(userId);
                        channelOnlineSelfPlatform.setGmtCreate(nowDateTime);
                        channelOnlineSelfPlatform.setModifiedId(userId);
                        channelOnlineSelfPlatform.setGmtModified(nowDateTime);
                        channelOnlineSelfPlatform.setIsDeleted(IsDeletedCode.NO.getCode());
                        airportExpressChannelOnlineSelfPlatformList.add(channelOnlineSelfPlatform);
                        // 插入加幅规则
                        AirportExpressIncreaseStrategyRule increaseStrategyRule = EntityUtil.copy(channelOnlineSelfPlatformReq.getAirportExpressIncreaseStrategyRule(), AirportExpressIncreaseStrategyRule.class);
                        increaseStrategyRule.setId(SnowflakeIdWorker.nextId());
                        increaseStrategyRule.setIncreaseStrategyId(increaseStrategy.getId());
                        increaseStrategyRule.setCustomId(channelOnlineSelfPlatform.getId());
                        increaseStrategyRule.setSoldNumber(null);
                        airportExpressIncreaseStrategyRuleList.add(increaseStrategyRule);
                    });
                }
                // 线上第三方
                if (CollectionUtils.isNotEmpty(increaseStrategyReq.getAirportExpressChannelOnlineThirdPlatformList())) {
                    increaseStrategyReq.getAirportExpressChannelOnlineThirdPlatformList().forEach(channelOnlineThirdPlatformReq -> {
                        AirportExpressChannelOnlineThirdPlatform channelOnlineSelfPlatform = EntityUtil.copy(channelOnlineThirdPlatformReq, AirportExpressChannelOnlineThirdPlatform.class);
                        channelOnlineSelfPlatform.setId(SnowflakeIdWorker.nextId());
                        channelOnlineSelfPlatform.setIncreaseStrategyId(increaseStrategy.getId());
                        channelOnlineSelfPlatform.setCreateId(userId);
                        channelOnlineSelfPlatform.setGmtCreate(nowDateTime);
                        channelOnlineSelfPlatform.setModifiedId(userId);
                        channelOnlineSelfPlatform.setGmtModified(nowDateTime);
                        channelOnlineSelfPlatform.setIsDeleted(IsDeletedCode.NO.getCode());
                        airportExpressChannelOnlineThirdPlatformList.add(channelOnlineSelfPlatform);
                        // 插入加幅规则
                        AirportExpressIncreaseStrategyRule increaseStrategyRule = EntityUtil.copy(channelOnlineThirdPlatformReq.getAirportExpressIncreaseStrategyRule(), AirportExpressIncreaseStrategyRule.class);
                        increaseStrategyRule.setId(SnowflakeIdWorker.nextId());
                        increaseStrategyRule.setIncreaseStrategyId(increaseStrategy.getId());
                        increaseStrategyRule.setCustomId(channelOnlineSelfPlatform.getId());
                        increaseStrategyRule.setSoldNumber(null);
                        airportExpressIncreaseStrategyRuleList.add(increaseStrategyRule);
                    });
                }
                airportExpressIncreaseStrategyList.add(increaseStrategy);
            }
        }
        insertBatchSomeColumn(airportExpressIncreaseStrategyList, airportExpressIncreaseStrategyMapper);
        insertBatchSomeColumn(airportExpressIncreaseStrategyDateList, airportExpressIncreaseStrategyDateMapper);
        insertBatchSomeColumn(airportExpressIncreaseStrategyRuleList, airportExpressIncreaseStrategyRuleMapper);
        insertBatchSomeColumn(airportExpressChannelOfflineAgentCustomList, airportExpressChannelOfflineAgentCustomMapper);
        insertBatchSomeColumn(airportExpressChannelOfflineSelfCustomList, airportExpressChannelOfflineSelfCustomMapper);
        insertBatchSomeColumn(airportExpressChannelOnlineSelfPlatformList, airportExpressChannelOnlineSelfPlatformMapper);
        insertBatchSomeColumn(airportExpressChannelOnlineThirdPlatformList, airportExpressChannelOnlineThirdPlatformMapper);
        /**
         * 更新产品redis缓存
         */
        CompletableFuture.runAsync(() -> {
            log.info("【机场快线-批量保存加幅策略】更新redis缓存开始, data:{}", JSON.toJSONString(airportExpressIdList));
            airportExpressAppService.cacheInit();
        });
        return Result.success();
    }

    private void checkSaveData(List<AirportExpress> airportExpresses, List<AirportExpressIncreaseStrategyReq> airportExpressIncreaseStrategyReqList) {
        boolean isSingle = false;
        boolean isRound = false;
        for (AirportExpress airportExpress : airportExpresses) {
            if (airportExpress.getTicketType().equals(1)) {
                // 单程票
                isSingle = true;
            } else {
                // 往返票
                isRound = true;
            }
        }
        AirportExpressStrategyRuleValidator airportExpressStrategyRuleValidator = null;
        if (isSingle && !isRound) {// 单程票
            airportExpressStrategyRuleValidator = new AirportExpressStrategyRuleSingleValidator();
        } else if (!isSingle && isRound) {// 往返票
            airportExpressStrategyRuleValidator = new AirportExpressStrategyRuleRoundValidator();
        } else if (isSingle && isRound) {// 单程票+往返票
            airportExpressStrategyRuleValidator = new AirportExpressStrategyRuleSingleRoundValidator();
        }
        for (AirportExpressIncreaseStrategyReq increaseStrategyReq : airportExpressIncreaseStrategyReqList) {
            // 自营价格校验
            if (Objects.equals(OrderAirexpressConstants.SALE_CHANNEL_TYPE_ALL, increaseStrategyReq.getSelfSalePermissionType())) {
                airportExpressStrategyRuleValidator.validate(increaseStrategyReq.getAirportExpressIncreaseStrategySelfRule());
            } else if (Objects.equals(OrderAirexpressConstants.SALE_CHANNEL_TYPE_SELECTED, increaseStrategyReq.getSelfSalePermissionType())) {
                List<AirportExpressIncreaseStrategyRuleReq> ruleReqList = increaseStrategyReq.getAirportExpressChannelOfflineSelfCustomList().stream().map(AirportExpressChannelOfflineSelfCustomReq::getAirportExpressIncreaseStrategyRule).collect(Collectors.toList());
                airportExpressStrategyRuleValidator.validate(ruleReqList);
            }
            // 代理价格校验
            if (Objects.equals(OrderAirexpressConstants.SALE_CHANNEL_TYPE_ALL, increaseStrategyReq.getAgentSalePermissionType())) {
                airportExpressStrategyRuleValidator.validate(increaseStrategyReq.getAirportExpressIncreaseStrategyAgentRule());
            } else if (Objects.equals(OrderAirexpressConstants.SALE_CHANNEL_TYPE_SELECTED, increaseStrategyReq.getAgentSalePermissionType())) {
                List<AirportExpressIncreaseStrategyRuleReq> ruleReqList = increaseStrategyReq.getAirportExpressChannelOfflineAgentCustomList().stream().map(AirportExpressChannelOfflineAgentCustomReq::getAirportExpressIncreaseStrategyRule).collect(Collectors.toList());
                airportExpressStrategyRuleValidator.validate(ruleReqList);
            }
        }
    }

    private void insertBatchSomeColumn(List list, CustomBaseMapper mapper) {
        if (CollectionUtils.isNotEmpty(list)) {
            mapper.insertBatchSomeColumn(list);
        }
    }

    @Override
    public List<AirportExpressIncreaseStrategyDTO> selectAirportExpressListByExpressId(Long expressId) {
        // 查询加幅策略列表
        List<AirportExpressIncreaseStrategy> airportExpressIncreaseStrategyList = airportExpressIncreaseStrategyMapper.selectList(new QueryWrapper<AirportExpressIncreaseStrategy>().lambda()
                .eq(AirportExpressIncreaseStrategy::getAirportExpressId, expressId));
        List<AirportExpressIncreaseStrategyDTO> airportExpressDTOS = EntityUtil.copyList(airportExpressIncreaseStrategyList, AirportExpressIncreaseStrategyDTO.class);
        for (AirportExpressIncreaseStrategyDTO aeIncreaseStrategyDTO : airportExpressDTOS) {
            // 查询加幅策略-日期列表
            List<AirportExpressIncreaseStrategyDate> aeIncreaseStrategyDates = airportExpressIncreaseStrategyDateMapper.selectList(new QueryWrapper<AirportExpressIncreaseStrategyDate>().lambda()
                    .eq(AirportExpressIncreaseStrategyDate::getIncreaseStrategyId, aeIncreaseStrategyDTO.getId()));
            aeIncreaseStrategyDTO.setAirportExpressIncreaseStrategyDateList(EntityUtil.copyList(aeIncreaseStrategyDates, AirportExpressIncreaseStrategyDateDTO.class));
            // 查询加幅策略-规则列表
            List<AirportExpressIncreaseStrategyRule> aeIncreaseStrategyRules = airportExpressIncreaseStrategyRuleMapper.selectList(new QueryWrapper<AirportExpressIncreaseStrategyRule>().lambda()
                    .eq(AirportExpressIncreaseStrategyRule::getIncreaseStrategyId, aeIncreaseStrategyDTO.getId()));
            List<AirportExpressIncreaseStrategyRuleDTO> aeIncreaseStrategyRuleDTOs = EntityUtil.copyList(aeIncreaseStrategyRules, AirportExpressIncreaseStrategyRuleDTO.class);
            // 查询加幅策略-线下自营
            if (aeIncreaseStrategyDTO.getSelfSalePermissionType() != null) {
                if (OrderAirexpressConstants.SALE_CHANNEL_TYPE_ALL == aeIncreaseStrategyDTO.getSelfSalePermissionType()) {
                    List<AirportExpressIncreaseStrategyRuleDTO> ruleList = aeIncreaseStrategyRuleDTOs.stream().filter(ruleDTO -> ruleDTO.getId().equals(aeIncreaseStrategyDTO.getSelfSalePermissionId())).collect(Collectors.toList());
                    aeIncreaseStrategyDTO.setAirportExpressIncreaseStrategySelfRule(ruleList.get(0));
                }
                if (OrderAirexpressConstants.SALE_CHANNEL_TYPE_SELECTED == aeIncreaseStrategyDTO.getSelfSalePermissionType()) {
                    List<AirportExpressChannelOfflineSelfCustom> aeChannelOfflineSelfCustoms = airportExpressChannelOfflineSelfCustomMapper.selectList(new QueryWrapper<AirportExpressChannelOfflineSelfCustom>().lambda()
                            .eq(AirportExpressChannelOfflineSelfCustom::getIncreaseStrategyId, aeIncreaseStrategyDTO.getId())
                            .eq(AirportExpressChannelOfflineSelfCustom::getIsDeleted, IsDeletedCode.NO.getCode()));
                    if (CollectionUtils.isNotEmpty(aeChannelOfflineSelfCustoms)) {
                        List<AirportExpressChannelOfflineSelfCustomDTO> aeChannelOfflineSelfCustomDTOs = EntityUtil.copyList(aeChannelOfflineSelfCustoms, AirportExpressChannelOfflineSelfCustomDTO.class);
                        // 组装所属加幅规则
                        for (AirportExpressChannelOfflineSelfCustomDTO aeChannelOfflineSelfCustomDTO : aeChannelOfflineSelfCustomDTOs) {
                            List<AirportExpressIncreaseStrategyRuleDTO> ruleList = aeIncreaseStrategyRuleDTOs.stream().filter(ruleDTO -> aeChannelOfflineSelfCustomDTO.getId().equals(ruleDTO.getCustomId())).collect(Collectors.toList());
                            if (CollectionUtils.isNotEmpty(ruleList)) {
                                aeChannelOfflineSelfCustomDTO.setAirportExpressIncreaseStrategyRule(ruleList.get(0));
                            }
                        }
                        aeIncreaseStrategyDTO.setAirportExpressChannelOfflineSelfCustomList(aeChannelOfflineSelfCustomDTOs);
                    }
                }
            }
            // 查询加幅策略-线下代理
            if (aeIncreaseStrategyDTO.getAgentSalePermissionType() != null) {
                if (OrderAirexpressConstants.SALE_CHANNEL_TYPE_ALL == aeIncreaseStrategyDTO.getAgentSalePermissionType()) {
                    List<AirportExpressIncreaseStrategyRuleDTO> ruleList = aeIncreaseStrategyRuleDTOs.stream().filter(ruleDTO -> ruleDTO.getId().equals(aeIncreaseStrategyDTO.getAgentSalePermissionId())).collect(Collectors.toList());
                    aeIncreaseStrategyDTO.setAirportExpressIncreaseStrategyAgentRule(ruleList.get(0));
                }
                if (OrderAirexpressConstants.SALE_CHANNEL_TYPE_SELECTED == aeIncreaseStrategyDTO.getAgentSalePermissionType()) {
                    List<AirportExpressChannelOfflineAgentCustom> aeChannelOfflineAgentCustoms = airportExpressChannelOfflineAgentCustomMapper.selectList(new QueryWrapper<AirportExpressChannelOfflineAgentCustom>().lambda()
                            .eq(AirportExpressChannelOfflineAgentCustom::getIncreaseStrategyId, aeIncreaseStrategyDTO.getId())
                            .eq(AirportExpressChannelOfflineAgentCustom::getIsDeleted, IsDeletedCode.NO.getCode()));
                    if (CollectionUtils.isNotEmpty(aeChannelOfflineAgentCustoms)) {
                        List<AirportExpressChannelOfflineAgentCustomDTO> aeChannelOfflineAgentCustomDTOs = EntityUtil.copyList(aeChannelOfflineAgentCustoms, AirportExpressChannelOfflineAgentCustomDTO.class);
                        // 组装所属加幅规则
                        for (AirportExpressChannelOfflineAgentCustomDTO aeChannelOfflineAgentCustomDTO : aeChannelOfflineAgentCustomDTOs) {
                            List<AirportExpressIncreaseStrategyRuleDTO> ruleList = aeIncreaseStrategyRuleDTOs.stream().filter(ruleDTO -> aeChannelOfflineAgentCustomDTO.getId().equals(ruleDTO.getCustomId())).collect(Collectors.toList());
                            if (CollectionUtils.isNotEmpty(ruleList)) {
                                aeChannelOfflineAgentCustomDTO.setAirportExpressIncreaseStrategyRule(ruleList.get(0));
                            }
                        }
                        aeIncreaseStrategyDTO.setAirportExpressChannelOfflineAgentCustomList(aeChannelOfflineAgentCustomDTOs);
                    }
                }
            }
            // 查询加幅策略-线上自营
            List<AirportExpressChannelOnlineSelfPlatform> aeChannelOnlineSelfPlatforms = airportExpressChannelOnlineSelfPlatformMapper.selectList(new QueryWrapper<AirportExpressChannelOnlineSelfPlatform>().lambda()
                    .eq(AirportExpressChannelOnlineSelfPlatform::getIncreaseStrategyId, aeIncreaseStrategyDTO.getId())
                    .eq(AirportExpressChannelOnlineSelfPlatform::getIsDeleted, IsDeletedCode.NO.getCode()));
            if (CollectionUtils.isNotEmpty(aeChannelOnlineSelfPlatforms)) {
                List<AirportExpressChannelOnlineSelfPlatformDTO> aeChannelOnlineSelfPlatformDTOs = EntityUtil.copyList(aeChannelOnlineSelfPlatforms, AirportExpressChannelOnlineSelfPlatformDTO.class);
                // 组装所属加幅规则
                for (AirportExpressChannelOnlineSelfPlatformDTO aeChannelOnlineSelfPlatformDTO : aeChannelOnlineSelfPlatformDTOs) {
                    List<AirportExpressIncreaseStrategyRuleDTO> ruleList = aeIncreaseStrategyRuleDTOs.stream().filter(ruleDTO -> aeChannelOnlineSelfPlatformDTO.getId().equals(ruleDTO.getCustomId())).collect(Collectors.toList());
                    if (CollectionUtils.isNotEmpty(ruleList)) {
                        aeChannelOnlineSelfPlatformDTO.setAirportExpressIncreaseStrategyRule(ruleList.get(0));
                    }
                }
                aeIncreaseStrategyDTO.setAirportExpressChannelOnlineSelfPlatformList(aeChannelOnlineSelfPlatformDTOs);
            }
            // 查询加幅策略-线上第三方
            List<AirportExpressChannelOnlineThirdPlatform> aeChannelOnlineThirds = airportExpressChannelOnlineThirdPlatformMapper.selectList(new QueryWrapper<AirportExpressChannelOnlineThirdPlatform>().lambda()
                    .eq(AirportExpressChannelOnlineThirdPlatform::getIncreaseStrategyId, aeIncreaseStrategyDTO.getId())
                    .eq(AirportExpressChannelOnlineThirdPlatform::getIsDeleted, IsDeletedCode.NO.getCode()));
            if (CollectionUtils.isNotEmpty(aeChannelOnlineThirds)) {
                List<AirportExpressChannelOnlineThirdPlatformDTO> aeChannelOnlineThirdPlatformDTOs = EntityUtil.copyList(aeChannelOnlineThirds, AirportExpressChannelOnlineThirdPlatformDTO.class);
                // 组装所属加幅规则
                for (AirportExpressChannelOnlineThirdPlatformDTO aeChannelOnlineThirdPlatformDTO : aeChannelOnlineThirdPlatformDTOs) {
                    List<AirportExpressIncreaseStrategyRuleDTO> ruleList = aeIncreaseStrategyRuleDTOs.stream().filter(ruleDTO -> aeChannelOnlineThirdPlatformDTO.getId().equals(ruleDTO.getCustomId())).collect(Collectors.toList());
                    if (CollectionUtils.isNotEmpty(ruleList)) {
                        aeChannelOnlineThirdPlatformDTO.setAirportExpressIncreaseStrategyRule(ruleList.get(0));
                    }
                }
                aeIncreaseStrategyDTO.setAirportExpressChannelOnlineThirdPlatformList(aeChannelOnlineThirdPlatformDTOs);
            }
        }
        return airportExpressDTOS;
    }

    /**
     * 根据机场快线id删除策略
     *
     * @param airportExpressIds 机场快线id列表
     */
    private void deleteStrategyByAirportExpressId(List<Long> airportExpressIds) {
        if (CollectionUtils.isNotEmpty(airportExpressIds)) {
            List<Long> increaseStrategyIds = airportExpressIncreaseStrategyMapper.selectIdListByAirportExpressIds(airportExpressIds);
            if (CollectionUtils.isNotEmpty(increaseStrategyIds)) {
                airportExpressChannelOfflineSelfCustomMapper.delete(new QueryWrapper<AirportExpressChannelOfflineSelfCustom>().lambda().in(AirportExpressChannelOfflineSelfCustom::getIncreaseStrategyId, increaseStrategyIds));
                airportExpressChannelOfflineAgentCustomMapper.delete(new QueryWrapper<AirportExpressChannelOfflineAgentCustom>().lambda().in(AirportExpressChannelOfflineAgentCustom::getIncreaseStrategyId, increaseStrategyIds));
                airportExpressChannelOnlineSelfPlatformMapper.delete(new QueryWrapper<AirportExpressChannelOnlineSelfPlatform>().lambda().in(AirportExpressChannelOnlineSelfPlatform::getIncreaseStrategyId, increaseStrategyIds));
                airportExpressChannelOnlineThirdPlatformMapper.delete(new QueryWrapper<AirportExpressChannelOnlineThirdPlatform>().lambda().in(AirportExpressChannelOnlineThirdPlatform::getIncreaseStrategyId, increaseStrategyIds));
                airportExpressIncreaseStrategyRuleMapper.delete(new QueryWrapper<AirportExpressIncreaseStrategyRule>().lambda().in(AirportExpressIncreaseStrategyRule::getIncreaseStrategyId, increaseStrategyIds));
                airportExpressIncreaseStrategyDateMapper.delete(new QueryWrapper<AirportExpressIncreaseStrategyDate>().lambda().in(AirportExpressIncreaseStrategyDate::getIncreaseStrategyId, increaseStrategyIds));
                airportExpressIncreaseStrategyMapper.delete(new QueryWrapper<AirportExpressIncreaseStrategy>().lambda().in(AirportExpressIncreaseStrategy::getId, increaseStrategyIds));
            }
        }
    }

    class AirportExpressStrategyRuleSingleValidator extends AirportExpressStrategyRuleValidator {
        public AirportExpressStrategyRuleSingleValidator() {
        }

        public void validate(AirportExpressIncreaseStrategyRuleReq airportExpressIncreaseStrategyRuleReq) {
            if (airportExpressIncreaseStrategyRuleReq.getAdultOneWayPriceType() == null) {
                throw new BusinessException(SystemError.SYS_418, "成人单程价格类型");
            }
            if (airportExpressIncreaseStrategyRuleReq.getAdultOneWayPrice() == null || airportExpressIncreaseStrategyRuleReq.getAdultOneWayPrice().compareTo(BigDecimal.ZERO) < 0) {
                throw new BusinessException(SystemError.SYS_418, "成人单程价格");
            }
            if (airportExpressIncreaseStrategyRuleReq.getChildrenOneWayPriceType() == null) {
                throw new BusinessException(SystemError.SYS_418, "小童单程价格类型");
            }
            if (airportExpressIncreaseStrategyRuleReq.getChildrenOneWayPrice() == null || airportExpressIncreaseStrategyRuleReq.getChildrenOneWayPrice().compareTo(BigDecimal.ZERO) < 0) {
                throw new BusinessException(SystemError.SYS_418, "小童单程价格");
            }
        }
    }

    class AirportExpressStrategyRuleRoundValidator extends AirportExpressStrategyRuleValidator {
        public void validate(AirportExpressIncreaseStrategyRuleReq airportExpressIncreaseStrategyRuleReq) {
            if (airportExpressIncreaseStrategyRuleReq.getAdultRoundTripPriceType() == null) {
                throw new BusinessException(SystemError.SYS_418, "成人往返价格类型");
            }
            if (airportExpressIncreaseStrategyRuleReq.getAdultRoundTripPrice() == null || airportExpressIncreaseStrategyRuleReq.getAdultRoundTripPrice().compareTo(BigDecimal.ZERO) < 0) {
                throw new BusinessException(SystemError.SYS_418, "成人往返价格");
            }
        }
    }

    class AirportExpressStrategyRuleSingleRoundValidator extends AirportExpressStrategyRuleValidator {
        public void validate(AirportExpressIncreaseStrategyRuleReq airportExpressIncreaseStrategyRuleReq) {
            if (airportExpressIncreaseStrategyRuleReq.getAdultOneWayPriceType() == null) {
                throw new BusinessException(SystemError.SYS_418, "成人单程价格类型");
            }
            if (airportExpressIncreaseStrategyRuleReq.getAdultOneWayPrice() == null || airportExpressIncreaseStrategyRuleReq.getAdultOneWayPrice().compareTo(BigDecimal.ZERO) < 0) {
                throw new BusinessException(SystemError.SYS_418, "成人单程价格");
            }
            if (airportExpressIncreaseStrategyRuleReq.getChildrenOneWayPriceType() == null) {
                throw new BusinessException(SystemError.SYS_418, "小童单程价格类型");
            }
            if (airportExpressIncreaseStrategyRuleReq.getChildrenOneWayPrice() == null || airportExpressIncreaseStrategyRuleReq.getChildrenOneWayPrice().compareTo(BigDecimal.ZERO) < 0) {
                throw new BusinessException(SystemError.SYS_418, "小童单程价格");
            }
            if (airportExpressIncreaseStrategyRuleReq.getAdultRoundTripPriceType() == null) {
                throw new BusinessException(SystemError.SYS_418, "成人往返价格类型");
            }
            if (airportExpressIncreaseStrategyRuleReq.getAdultRoundTripPrice() == null || airportExpressIncreaseStrategyRuleReq.getAdultRoundTripPrice().compareTo(BigDecimal.ZERO) < 0) {
                throw new BusinessException(SystemError.SYS_418, "成人往返价格");
            }

        }
    }
}